<!DOCTYPE html>
<html class="pixel-ratio-1 watch-active-state">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="theme-color" content="">
    <title>注册</title>
    <link rel="stylesheet" href="/resources/wap/css/framework7_002.css">
    <link rel="stylesheet" href="/resources/wap/css/style.css">

    <script src="/resources/common/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="/resources/common/js/md5.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/self.js"></script>
    <style type="text/css">

        .img-div{
            text-align: center;
            background: url("/resources/wap/image/add_hi.png") no-repeat center;
            height: 200px;
        }
    </style>

</head>
<body>
<div class="turnon"></div>
<div class="navbar">
    <div class="navbar-inner">
        <div class="center"><a href="login.html">认证</a></div>
    </div>
</div>

<div class="dlbox">
    <div>
        营业执照
    </div>
    <div  class="img-div" style="vertical-align: middle;text-align: center;" onclick="$('#fileUpload').click()">
        <img name="license"  height="160px" src=""/></div>
    <input style="display:none"  accept="image/*" type="file" value="" id="fileUpload" name="file"
           onchange="uploadImage(this)">
    <div style="clear: both"></div>
</div>



<div class="dlbox auditStatus" style="display: none">
    <div>
        审核状态
    </div>
    <input name="auditStatus" class="dlyhm" type="text" readonly  />
</div>

<div class="dlbox auditDesc" style="display: none">
    <div>
        审核备注
    </div>
    <textarea  style="height:40px;width: 100%;border: none !important;border-bottom: 1px solid;"
               name="auditDesc" readonly></textarea>
</div>


<!--<div class="zcbox"><input name="" class="zcyhm" type="text" placeholder="验证码" foundfield="" compareway="2">

    <div class="fsyzm">发送验证码</div>
</div>-->
<div class="zcbut register"><a href="javascript:void(0)" onclick="save();">保存</a></div>

</body>
<script type="text/javascript">

    $(function () {
        loadData();
    });
    function loadData() {
        $.ajax({
            url:"/wap/customer/getUser.do",
            data:{},
            type:'post',
            dataType:'json',
            success:function(data){
                console.log(data);
                if(data.success){
                    if(!isNullOrUndefined(data.data)){
                        var customer =  data.data;
                        $("[name='license']").attr("src",data.data.license);
                        $("[name='auditStatus']").val(getAuditStatusName(data.data.auditStatus));
                        $("[name='auditDesc']").html(data.data.auditDesc);

                        if(customer.auditStatus == 'fail'){
                            $(".auditDesc").show();
                        }
                        if(customer.auditStatus != 'noInit'){
                            $(".auditStatus").show();
                        }

                    }

                }
            }
        });
    }
    function uploadImage(node) {
        $.ajaxFileUpload({
            url: "/uploadImage.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
            secureuri: false,//是否启用安全提交，默认为false
            fileElementId: $(node).attr("id"),                        //文件选择框的id属性
            dataType: 'json',                                     //服务器返回的格式，可以是json, xml
            success: function (data, status) {  //服务器成功响应处理函数
                if (data.success) {
                    var image = data.data;
                    $("[name='license']").attr("src",image);

                } else {
                    alert(data.msg);
                }
            },
            error: function (data, status, e) { //服务器响应失败处理函数

            }
        });
    }

    function save() {
        var params = {};
        params['license'] = $("[name='license']").attr("src");
        $.ajax({
            url: "/wap/customer/certify.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                } else {
                    alert(data.msg);
                }
            }
        });
    }

    function getAuditStatusName(auditStatus) {
        var name = "";
        if(auditStatus == 'noInit'){
            name ="未提交";
        }else if(auditStatus == 'init'){
            name ="待审核";
        }else if(auditStatus == 'pass'){
            name ="审核通过";
        }else if(auditStatus == 'fail'){
            name ="审核失败";
        }
        return name;

    }

</script>
</html>